/**
 * 保存数据至本地
 * @param key
 * @param value
 */
export const localSave = (key: string, value: any) => {
  let data = value;
  if (typeof data === 'object') {
    data = JSON.stringify(value);
  }
  localStorage.setItem(key, data);
};

/**
 * 读取本地数据
 * @param key
 * @returns
 */
export const localRead = (key: string) => {
  const data = localStorage.getItem(key) || '';
  try {
    return JSON.parse(data);
  } catch (err) {
    return data;
  }
};

/**
 * 移除本地数据
 * @param key
 */
export const localRemove = (key: string) => {
  localStorage.removeItem(key);
};
